#!/bin/bash

# RocketMQ Docker 环境启动脚本

echo "🚀 启动 RocketMQ Docker 环境..."

# 检查 Docker 是否运行
if ! docker info > /dev/null 2>&1; then
    echo "❌ Docker 未运行，请先启动 Docker"
    exit 1
fi

# 创建必要的目录
echo "📁 创建必要的目录..."
mkdir -p logs/nameserver logs/broker store/nameserver store/broker

# 构建 Python 客户端镜像
echo "🔨 构建 Python 客户端镜像..."
docker-compose build python-client

# 启动 RocketMQ 服务
echo "🔄 启动 RocketMQ 服务..."
docker-compose up -d nameserver broker console

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 10

# 检查服务状态
echo "🔍 检查服务状态..."
docker-compose ps

echo ""
echo "✅ RocketMQ 环境启动完成！"
echo ""
echo "📊 服务访问地址："
echo "   - NameServer: localhost:9876"
echo "   - Broker: localhost:10911"
echo "   - 管理控制台: http://localhost:8080"
echo ""
echo "🐍 进入 Python 客户端环境："
echo "   docker-compose run --rm python-client"
echo ""
echo "📝 常用命令："
echo "   - 查看日志: docker-compose logs -f"
echo "   - 停止服务: docker-compose down"
echo "   - 重启服务: docker-compose restart" 